﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace Usermanagment.VisualDisplay
{
	
	using Usermanagment.DBConnection;
	public partial class Tabledata : Form
	{
		DBConnect dbc;
		DBDatafetch dft;
		String table;
		public Tabledata()
		{
			InitializeComponent();
			this.MaximumSize = this.MinimumSize = this.Size;
			comboBox1.Items.Add("");
			dataGridView1.Enabled = false;

		}

		public Tabledata(Usermanagment.DBConnection.DBConnect dbc)
			: this()
		{

			this.dbc = dbc;
			comboFill();
			
		}

		private void btnRefresh_Click(object sender, EventArgs e)
		{
			dataDisp();
		}

		private void comboFill()
		{
			if (dft == null)
			{
				dft = new DBDatafetch(this.dbc);
			}
			DataTable d = dft.getTables();
			
			foreach (DataRow row in d.Rows)
			{
				String s = String.Format("{0}", row.ItemArray[0]);
				comboBox1.Items.Add(s);
			}
		}

		private void dataDisp()
		{
			if (dft == null)
				dft = new DBDatafetch(this.dbc);
			if (table.Length > 0)
			{
				DataTable d = dft.getAllData(table);
				dataGridView1.DataSource = d;
			}
		}

		private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
		{
			table = comboBox1.SelectedItem + "";
		}
	}


}
